package com.lianxi;

import javafx.scene.shape.Path;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/4/7 16:12
 * @description
 */
public class T2 {
    public static void main(String[] args) throws IOException {
        //复制文件夹及文件夹下的文件，一层

        String path1 = "D:\\file\\test\\dir1";
        String path2 = "D:\\file\\test\\dir4";

        wenjianjia(path1, path2);

    }

    private static void wenjianjia(String path1, String path2) throws IOException {
        File file1 = new File(path1);

        File[] files1 = file1.listFiles();
        for (File file : files1) {
            if (file.isDirectory()){
                Files.createDirectories(Paths.get(path2 +"\\"+file.getName()));
                String p1 = file.getAbsolutePath();
                String p2 = path2 + "\\" + file.getName();
                wenjianjia(p1,p2);

            }
            fuzhi((path1 +"\\"+file.getName()),(path2 +"\\"+file.getName()));
        }
    }

    private static void fuzhi(String path1, String path2) {


        try {
            FileInputStream fis = new FileInputStream(path1);
            FileOutputStream fos = new FileOutputStream(path2);
            byte[] buff = new byte[1024];
            int len = 0;
            while ((len = fis.read(buff))!=-1){
                fos.write(buff,0,len);
            }
            fis.close();
            fos.close();


        } catch (FileNotFoundException e) {
//            e.printStackTrace();
        } catch (IOException e) {
//            e.printStackTrace();
        }
    }
}
